import { getClassifyTree, getlistClassifyTree } from '@/api/collection/classify';
import { getDictListByCode } from '@/api/sys/dict'
import { FormSchema } from '@/components/Form'
export const listClassifyTypeFormSchema: FormSchema[] = [
  {
    field: 'groupId',
    label: '分组ID',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'groupName',
    label: '分类名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
   {
    field: 'compare',
    label: '字段',
    component: 'Input',
    required: false,
  },
  {
    field: 'dataObtainType',
    label: '数据获取类型',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        {
            label: '分组',
            value: 0,
            key: '1'
        },
        {
            label: '系统计算',
            value: 1,
            key: '2'
        },
        {
            label: '单价',
            value: 2,
            key: '3'
        },
        {
            label: '手工录入',
            value: 3,
            key: '4'
        },
        {
            label: '固定值',
            value: 4,
            key: '5'
        },
        {
            label: '合计',
            value: 5,
            key: '6'
        },
        {
            label: '分组计算',
            value: 6,
            key: '7'
        },
        {
            label: '固定值（字符串）',
            value: 7,
            key: '8'
        }
      ],
    },
  },
  {
    field: 'energyType',
    label: '能源类型',
    component: 'ApiSelect',
    required: true,
    ifShow: ({values}) => values.dataObtainType === 2 ? true : false,
    componentProps: ({ formModel, formActionType }) => {
      return {
        api: getDictListByCode,
        params: 'energy_type',
        labelField: 'itemName',
        valueField: 'itemCode',
      }
    },
  },
  {
    field: 'value',
    label: '固定值',
    component: 'InputNumber',
    show: ({values}) => values.dataObtainType === 4 ? true : false
  },
    {
    field: 'fixedValue',
    label: '固定值(字符串)',
    component: 'Input',
    show: ({values}) => values.dataObtainType === 7 ? true : false
  },
  {
    field: 'classifyIds',
    label: '数据分类',
    component: 'ApiTree',
    show: ({values}) => values.dataObtainType === 1 ? true : false,
    componentProps: ({formModel, formActionType}) => {
        return {
            api: getClassifyTree,
            fieldNames: { key: 'classifyId', title: 'classifyName' },
            checkable: true,
            checkStrictly: true,
            checkedKeys: formModel.classifyIds,
            onCheck: (checkkeys) => {
                console.log(checkkeys)
                formModel.classifyIds = checkkeys.checked
            }
        }
    }
  },
   {
    field: 'sonGroupIds',
    label: '表单分类',
    component: 'ApiTree',
    show: ({values}) => values.dataObtainType === 5 ? true : false,
    componentProps: ({formModel, formActionType}) => {
        return {
            api: getlistClassifyTree,
            fieldNames: { key: 'groupId', title: 'groupName' },
            checkable: true,
            checkStrictly: true,
            checkedKeys: formModel.sonGroupIds,
            onCheck: (checkkeys) => {
                console.log(checkkeys)
                formModel.sonGroupIds = checkkeys.checked
            }
        }
    }
  },
  {
    field: 'functionDesc',
    label: '公式',
    show: ({values}) => values.dataObtainType === 6 ? true : false,
    slot: 'sumary'
  },
  {
    field: 'functionId',
    label: '公式',
    slot: 'functionId',
    ifShow: false
  },
  {
    field: 'countLevel',
    label: '计算级别',
    component: 'InputNumber',
    ifShow: ({values}) => values.dataObtainType === 6 ? true : false,
    required: true,
  },
  {
    field: 'dataType',
    label: '指标类型',
    component: 'Select',
    ifShow: ({values}) => values.dataObtainType === 1 ? true : false,
    required: true,
    componentProps: {
      options: [
        {
          label: '费用',
          value: 1,
          key: '1'
        },
        {
          label: '用量',
          value: 2,
          key: '2'
        }
      ]
    }
  },
  {
    field: 'description',
    label: '描述',
    component: 'InputTextArea',
    componentProps: {
      autoSize: { minRows: 3, maxRows: 5 },
    },
  },
]